import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _create_class } from "@swc/helpers/_/_create_class";
import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
import OAuth2Window from "./utils";
import { INSTAGRAM_APPID, REDIRECT_URI } from "./config";
var InsAuth = /*#__PURE__*/ function _target() {
    "use strict";
    function InsAuth() {
        var _this = this;
        _class_call_check(this, InsAuth);
        _define_property(this, "load", true);
        _define_property(this, "getCode", function() {
            return new Promise(function(resolve, reject) {
                /** facebook 要求使用https 协议  回调地址需要在 管理界面添加    */ OAuth2Window.open("instagram", "https://api.instagram.com/oauth/authorize/?redirect_uri=".concat(encodeURIComponent(REDIRECT_URI), "&client_id=").concat(INSTAGRAM_APPID, "&response_type=code&scope=user_profile&state=").concat(JSON.stringify({
                    href: location.href
                })), {
                    width: "600",
                    height: "700"
                }).then(function(res) {
                    if (res.error) {
                        reject(res);
                        return;
                    }
                    resolve(res);
                }, reject);
            });
        });
        _define_property(this, "getAccessToken", function() {
            return new Promise(function(resolve, reject) {
                try {
                    _this.getCode().then(function(res) {
                        var code = res.code;
                    });
                } catch (err) {
                    reject(err);
                }
            });
        });
        if ((_instanceof(this, InsAuth) ? this.constructor : void 0) !== InsAuth) {
            return;
        }
        if (!InsAuth._instance) {
            InsAuth._instance = this;
        }
        /** 加载sdk */ return InsAuth._instance;
    }
    _create_class(InsAuth, [
        {
            key: "loadFBSdk",
            value: function loadFBSdk(cb, onError) {
                cb === null || cb === void 0 ? void 0 : cb();
            }
        },
        {
            key: "init",
            value: function init() {
                var _this = this;
                /** 假如 sdk 加载失败可以使用init 重新加载sdk */ return new Promise(function(resolve, reject) {
                    if (_this.load && window.FB) {
                        resolve(InsAuth._instance);
                        return;
                    }
                    _this.loadFBSdk(function() {
                        resolve(InsAuth._instance);
                    }, reject);
                });
            }
        }
    ], [
        {
            key: "getInstance",
            value: function getInstance() {
                if (!InsAuth._instance) {
                    InsAuth._instance = new InsAuth();
                }
                return InsAuth._instance;
            }
        }
    ]);
    return InsAuth;
}();
_define_property(InsAuth, "_instance", null);
export default InsAuth.getInstance();

 //# sourceMappingURL=instagram.js.map